﻿#ifndef SERIALPORTDATASOURCE_H
#define SERIALPORTDATASOURCE_H

#include "../stdaxf.h"
#if defined(__QT_ENV_US__)
#include <QtSerialPort/qserialport.h>
#elif defined(Q_OS_LINUX)
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#elif WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define    WIN32_LEAN_AND_MEAN
#endif // WIN32_LEAN_AND_MEAN
#include <Windows.h>
//#include "driver/CSerialPort.h"
#else
#endif


//NS_BEGIN_SensorManage
//该数据源使用同步读写的方式
class SerialPortDataSourceTool// : public IDataSource
{
public:
	SerialPortDataSourceTool(const char *path_utf, int baudrate);
	~SerialPortDataSourceTool();
public:
	bool IsEof();
private:
	void initial(const char *path_utf, int baudrate);
	void destroy();
public:
	void Send(const char *message, int count);
	int FetchNext(char *buf, int bufsize);
	void Close();
#ifdef __QT_ENV_US__
private:
	QSerialPort *msp;
#elif defined(Q_OS_LINUX)
private:
    int msp;

#elif defined(WIN32)

#define FUNCTION1
#ifdef FUNCTION1
private:
    HANDLE msp;
	void openSys(const char *path_utf, int baudrate);
#else
private:
	CSerialPort mySerialPort;//首先将之前定义的类实例化
#endif
#else
#endif
};
// NS_END_SINGLE
#endif // SERIALPORTDATASOURCE_H
